//=============================================================================
// PepperPot
//=============================================================================
class PepperPot extends WoEWeapon;

var PepperPotDart Dart;
var bool bBotForceFire;

var() ScriptedTexture DisplayTexture;
var() color DisplayTileColour;
var float LastTexTime;
var bool bTexUpdate;
var int StatusCounter;

var Texture ScreenTex;

replication
{
	reliable if(Role == ROLE_Authority)
		Dart;
}

simulated function BringUp(optional Weapon PrevWeapon)
{
	Super.BringUp(PrevWeapon);
}

//Draw useful info on the weapon model's display panel.
simulated event RenderTexture(ScriptedTexture Tex)
{
	bTexUpdate = true;

	//Draw main screen.
	Tex.DrawTile(0, 0, 256, 256, 0, 0, 256, 256, ScreenTex, DisplayTileColour);

	//Display lock status.
	if(Dart != None)
	{
		if(Dart.P != None)
		{
			//'LOCKED ON' message.
			Tex.DrawTile(43, 41, 173, 19, 38, 0, 173, 19, ScreenTex, DisplayTileColour);

			//Seek mode 'SWARM'
			Tex.DrawTile(152, 72, 78, 14, 172, 234, 78, 14, ScreenTex, DisplayTileColour);
		}
		else
		{
			//Seek mode 'SPREAD'
			Tex.DrawTile(152, 72, 82, 14, 86, 234, 82, 14, ScreenTex, DisplayTileColour);
		}
	}
	else
	{
		//Seek mode 'N/A'
		Tex.DrawTile(152, 72, 40, 14, 7, 234, 40, 14, ScreenTex, DisplayTileColour);
	}

	//First status line.
	if(StatusCounter > 1)
		Tex.DrawTile(187, 124, 40, 14, 46, 234, 40, 14, ScreenTex, DisplayTileColour);
	else
		Tex.DrawTile(187, 124, 40, 14, 7, 234, 40, 14, ScreenTex, DisplayTileColour);

	//Second status line.
	if(StatusCounter > 2)
		Tex.DrawTile(187, 142, 40, 14, 46, 234, 40, 14, ScreenTex, DisplayTileColour);
	else
		Tex.DrawTile(187, 142, 40, 14, 7, 234, 40, 14, ScreenTex, DisplayTileColour);

	//Third status line.
	if(StatusCounter > 3)
		Tex.DrawTile(187, 159, 40, 14, 46, 234, 40, 14, ScreenTex, DisplayTileColour);
	else
		Tex.DrawTile(187, 159, 40, 14, 7, 234, 40, 14, ScreenTex, DisplayTileColour);

	//Fourth status line.
	if(StatusCounter > 4)
		Tex.DrawTile(187, 177, 40, 14, 46, 234, 40, 14, ScreenTex, DisplayTileColour);
	else
		Tex.DrawTile(187, 177, 40, 14, 7, 234, 40, 14, ScreenTex, DisplayTileColour);

	//Fifth status line.
	if(StatusCounter > 5)
		Tex.DrawTile(187, 194, 40, 14, 46, 234, 40, 14, ScreenTex, DisplayTileColour);
	else
		Tex.DrawTile(187, 194, 40, 14, 7, 234, 40, 14, ScreenTex, DisplayTileColour);
}

simulated event WeaponTick(float DeltaTime)
{
	//Update display.
	if(bTexUpdate && Level.TimeSeconds - LastTexTime > 0.5 && DisplayTexture != None && DisplayTexture.Client == self)
	{
		bTexUpdate = false;
		LastTexTime = Level.TimeSeconds;

		StatusCounter++;

		DisplayTexture.Revision++;
	}
}

simulated function bool HasAmmo()
{
	//Ignore FireMode[1] which doesn't use any ammo.
	return (FireMode[0] != None && AmmoAmount(0) > 0);
}

//Best when used from long/medium range.
function float GetAIRating()
{
	local Bot B;
	local float EnemyDist;

	B = Bot(Instigator.Controller);

	if((B == None) || (B.Enemy == None))
		return AIRating;

	if(Dart != None && Dart.P == B.Enemy)
		return (AIRating + 0.4);

	EnemyDist = VSize(B.Enemy.Location - Instigator.Location);

	if(EnemyDist > 4000)
		return (AIRating + 0.2);
	else if(EnemyDist > 2000)
		return (AIRating + 0.3);
	else if(EnemyDist < 500)
		return (AIRating - 0.2);

	return AIRating;
}

//Normally bots will want to hit their enemy with a dart, then fire seeking rockets.
function byte BestMode()
{
	local bot B;
	local float EnemyDist;

	B = Bot(Instigator.Controller);

	if(B.Enemy == None)
		return 0;

	EnemyDist = VSize(B.Enemy.Location - Instigator.Location);
	bBotForceFire = true;

	if(Dart != None)
	{
		if(Dart.P != None && Dart.P == B.Enemy)
			return 0;
		if(Dart.LifeSpan > Dart.Default.LifeSpan - 0.5 && FRand() < 0.4)
			return 0;
		else if(EnemyDist < 1000 && FRand() < 0.3)
		{
			bBotForceFire = false;
			return 0;
		}
		else
			return 1;
	}
	else if(EnemyDist < 2000 && FRand() < 0.3)
		return 0;

	return 1;
}

//Don't get too close.
function float SuggestAttackStyle()
{
	local float EnemyDist;

	EnemyDist = VSize(Instigator.Controller.Enemy.Location - Owner.Location);

	if(EnemyDist < 500)
		return -1.5;
	else if(EnemyDist < 1000)
		return -0.7;
	else if(EnemyDist > 4000)
		return 0.5;
	else
		return 0.0;
}

//The effective damage radius is greater than the radius of individual rockets
//and greater still if they are seeking rockets.
function float GetDamageRadius()
{
	if(Dart != None && Dart.P == Bot(Instigator.Controller).Enemy)
		return Super.GetDamageRadius() * 5;
	else
		return Super.GetDamageRadius() * 2;
}

defaultproperties
{
     DisplayTexture=ScriptedTexture'TFMedia.PepperPot.PepperPotST'
     DisplayTileColour=(B=255,G=255,R=255,A=255)
     ScreenTex=Texture'TFMedia.PepperPot.PepperPotScreen'
     FireModeClass(0)=Class'taskforces.PepperPotFire'
     FireModeClass(1)=Class'taskforces.PepperPotAltFire'
     SelectSound=Sound'WeaponSounds.RocketLauncher.SwitchToRocketLauncher'
     SelectForce="SwitchToRocketLauncher"
     AIRating=0.700000
     CurrentRating=0.700000
     Description="PepperPot rockets are like bees: A single bee (or rocket in this case) is but a minor distraction, but a whole swarm of them can take down an enemy many thousands of times their size. Nine rockets can be launched simultaneously, which left to themselves will simply carry on in a straight line, as rockets like to do. However the PepperPot also comes with a dart gun which fires a dart fitted with a homing beacon. The rockets will automatically pick up the signal and home in on it with remarkable agility."
     EffectOffset=(X=50.000000,Y=1.000000,Z=10.000000)
     DisplayFOV=40.000000
     Priority=12
     HudColor=(G=0)
     SmallViewOffset=(X=30.000000,Y=8.000000,Z=-11.000000)
     CenteredRoll=0
     CustomCrosshair=15
     CustomCrossHairColor=(B=0,G=0)
     CustomCrossHairTextureName="Crosshairs.HUD.Crosshair_Triad2"
     InventoryGroup=8
     PickupClass=Class'taskforces.TFWLPickup'
     PlayerViewOffset=(X=22.000000,Y=6.000000,Z=-9.000000)
     PlayerViewPivot=(Yaw=16384,Roll=500)
     BobDamping=1.500000
     AttachmentClass=Class'taskforces.PepperPotAttachment'
     IconCoords=(Y1=280,X2=85,Y2=318)
     ItemName="PepperPot"
     Mesh=SkeletalMesh'TFSentinelA.PepperPot1st'
     DrawScale=0.350000
     Skins(0)=Shader'TFMedia.PepperPot.PepperPotShader'
     Skins(1)=Shader'TFMedia.PepperPot.PepperPotBarrelsShader'
}
